package com.elective.courseselect.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.elective.courseselect.entity.CharacterEntity;
import com.elective.courseselect.enums.CharacterType;
import com.elective.courseselect.service.CharacterService;
import com.elective.courseselect.service.impl.CharacterServiceImpl;
import com.elective.courseselect.utils.R;
import com.elective.status.StatusCode;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 学生性格、课程表标签
 *
 * @author lee
 * @email 943204006@qq.ccom
 * @date 2021-09-04 19:23:06
 */
@RestController
@RequestMapping("courseselect/character")
public class CharacterController {
    @Autowired
    private CharacterService characterService;

    /**
     * 列表
     */
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        R page = characterService.queryPage(params);
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @GetMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CharacterEntity character = characterService.getById(id);
        return R.ok().put("character", character);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody CharacterEntity character){
        R r = characterService.saveNew(character);
        return r;
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    public R update(@RequestBody CharacterEntity character){
		R r = characterService.updateByIdNew(character);
        return r;
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Integer[] ids) throws Exception {
		characterService.deleteCharacter(Arrays.asList(ids));
        return R.ok();
    }

    @ApiOperation("查询性格标签库")
    @GetMapping("/searchCharacterLabel")
    public R searchCharacterLabel() {
        CharacterEntity characterEntity = new CharacterEntity();
        characterEntity.setType(CharacterType.CHARACTER_LABEL);
        QueryWrapper<CharacterEntity> characterQuery = CharacterServiceImpl.createExample(characterEntity);
        List<CharacterEntity> list = characterService.list(characterQuery);
        return R.ok(StatusCode.OK,"查询标签库成功").put("list",list);
    }



    @ApiOperation("查询全部课程标签")
    @GetMapping("/searchCourserLabel")
    public R searchCourserLabel() {
        CharacterEntity characterEntity = new CharacterEntity();
        characterEntity.setType(CharacterType.CLASS_LABEL);
        QueryWrapper<CharacterEntity> characterQuery = CharacterServiceImpl.createExample(characterEntity);
        List<CharacterEntity> list = characterService.list(characterQuery);
        return R.ok(StatusCode.OK,"查询全部课程标签成功").put("list",list);
    }

}
